package org.cxy;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONObject;

import java.util.Arrays;
import java.util.List;

public class DeleteChatSessions {

    // =============== ⚠️ 注意：请替换为你自己的真实值 ===============
    private static final String BEARER_TOKEN = "R2JEvg2zR3263m166u2CKOw/s3jJtum9P9XTWuF9o+ZAo//H5mwopbIPGdXfttJy";
    private static final String COOKIES = "smidV2=20250924140802cbefb8992086ac1b2cb31859111fe7fc0041df10c1e139510; .thumbcache_6b2e5483f9d858d7c661c5e276b6a6ae=LXtTznT1Whandm4Lbqq51F30hcGtYTWSr8FVLS//N/NWtVA9IcJE9r1+TzuxYXH6TlGw2Bbhc7wXwXbAXp/axw%3D%3D; intercom-device-id-guh50jw4=c9f59b4f-3db1-417f-b152-48a7b253d752; HWWAFSESTIME=1758700922588; HWWAFSESID=7fb5c70344877d75e3c; ds_session_id=206c1eb8eab346d7ad409b79cd4667f4; intercom-session-guh50jw4=OVFReGxicUx2RkFtN1pEVm12a0gyUWRuTExHTlJwWDhmZmp6djN3MDZYOU5RR2tMRGtCZ3R5V2lvMFJKSU05VXc4Z2t5TWVRczZpd3lDUisvTVdUNmh2eEhaZUQ5ZDFCdGlQK3loOTNURlU9LS1Rc3pKMDlRTVJyQy9MeWRodEZUTk1nPT0%3D--e71a890744ae3ebce907ea8f01d9fe76ef85d993";

    private static final String API_URL = "https://chat.deepseek.com/api/v0/chat_session/delete";

    private static final List<String> sessionIds = Arrays.asList(
            "5f1d9d9d-d51f-4d8d-871d-d5d5d5d5d5d5",
            "6f1d9d9d-d51f-4d8d-871d-d5d5d5d5d5d5"
    );

    public static void main(String[] args) {
        System.out.println("开始批量删除 " + sessionIds.size() + " 个聊天会话...");

        int successCount = 0;
        int failCount = 0;

        for (String sessionId : sessionIds) {
            try {
                JSONObject requestBody = new JSONObject();
                requestBody.put("chat_session_id", sessionId);

                HttpResponse response = HttpRequest.post(API_URL)
                        .header("accept", "*/*")
                        .header("accept-language", "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7")
                        .header("authorization", "Bearer " + BEARER_TOKEN)
                        .header("content-type", "application/json")
                        .cookie(COOKIES)
                        .header("origin", "https://chat.deepseek.com")
                        .header("priority", "u=1, i")
                        .header("referer", "https://chat.deepseek.com/a/chat/s/" + sessionId)
                        .header("sec-ch-ua", "\"Google Chrome\";v=\"141\", \"Not?A_Brand\";v=\"8\", \"Chromium\";v=\"141\"")
                        .header("sec-ch-ua-mobile", "?0")
                        .header("sec-ch-ua-platform", "\"Windows\"")
                        .header("sec-fetch-dest", "empty")
                        .header("sec-fetch-mode", "cors")
                        .header("sec-fetch-site", "same-origin")
                        .header("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36")
                        .header("x-app-version", "20241129.1")
                        .header("x-client-locale", "zh_CN")
                        .header("x-client-platform", "web")
                        .header("x-client-version", "1.5.0")
                        .body(requestBody.toString())
                        .timeout(10000)
                        .execute();

                if (response.isOk()) {
                    System.out.println("✅ 成功删除: " + sessionId);
                    successCount++;
                } else {
                    System.err.println("❌ 删除失败 [" + sessionId + "] 状态码: " + response.getStatus() + ", 响应: " + response.body());
                    failCount++;
                }

                // 可选：防止请求过快被限流
                Thread.sleep(500);

            } catch (Exception e) {
                System.err.println("🔥 请求异常 [" + sessionId + "]: " + e.getMessage());
                failCount++;
                // 可选：打印堆栈
                // e.printStackTrace();
            }
        }

        System.out.println("\n===== 批量删除完成 =====");
        System.out.println("成功: " + successCount);
        System.out.println("失败: " + failCount);
        System.out.println("总计: " + sessionIds.size());
    }
}